package org.openharmony.qttool;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.intellij.openapi.ui.Messages;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class HarmonyQtConfig {
    private static final HarmonyQtConfig instance = new HarmonyQtConfig();

    private List<String> apis;

    private HarmonyQtConfig() {
        ObjectMapper objectMapper = new ObjectMapper();
        File jsonFile = new File(Utils.pluginPath() + "/data/config.json");
        try {
            JsonNode rootNode = objectMapper.readTree(jsonFile);
            JsonNode apisNode = rootNode.get("apis");
            if (apisNode != null && apisNode.isArray()) {
                apis = objectMapper.convertValue(apisNode,
                        objectMapper.getTypeFactory().constructCollectionType(List.class, String.class));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    public static HarmonyQtConfig getInstance() {
        return instance;
    }

    public List<String> getApis() {
        return apis;
    }
}
